
import { useEffect } from "react";
import { useNavigate, useLocation } from "react-router-dom";
import UserList from '../system/user-list'
import DeclarList from '../declaration/declar-List'
import DecDocument from '../declaration/decl-document'
import DocumentList from '../document/documentList'
import BaseList from '../system/base-list'
import CostList from '../cost/cost-list'
import CustomList from '../../pages/custom/custom-list.JSX'
import DataChart from '../../showdata/dataChart'

export const getMenus = () => {

  return [
    {
      key: "/showdata",
      path: "/showdata",
      label: "数据面板",
      roles: ["admin"],
      children: [
        {
          key: "/showdata/dataChart",
          path: "/showdata/dataChart",
          label: "数据图表",
          roles: ["admin"],
          element: <DataChart />
        },
      ]
    },
    {
      key: "/custom",
      path: "/custom",
      label: "客户管理",
      roles: ["admin", "staff"],
      children: [
        {
          key: "/custom/customList",
          path: "/custom/customList",
          label: "客户列表",
          roles: ["admin", "staff"],
          element: <CustomList />,
        },
      ]
    },
    {
      key: "/declaration",
      path: "/declaration",
      label: "报关管理",
      roles: ["admin", "staff"],
      children: [
        {
          key: "/declaration/decListIM",
          path: "/declaration/decListIM",
          label: "出口报关",
          roles: ["admin", "staff"],
          element: <DeclarList />,
        },
        {
          key: "/declaration/decListEM",
          path: "/declaration/decListEM",
          label: "进口报关",
          roles: ["admin", "staff"],
          element: <DeclarList />,
        },
        {
          key: "/declaration/declDocument",
          path: "/declaration/declDocument",
          label: "单证关联",
          roles: ["admin", "staff"],
          element: <DecDocument />,
        },
      ]
    },
    {
      key: "/document",
      path: "/document",
      label: "单证管理",
      roles: ["admin", "staff"],
      children: [
        {
          key: "/document/documentList",
          path: "/document/documentList",
          label: "单证列表",
          roles: ["admin", "staff"],
          element: <DocumentList />,
        }

      ]
    },
    {
      key: "/cost",
      path: "/cost",
      label: "费用管理",
      roles: ["admin", "staff"],
      children: [
        {
          key: "/cost/costList",
          path: "/cost/costList",
          label: "费用列表",
          roles: ["admin", "staff"],
          element: <CostList />,
        }

      ]
    },

    {
      key: "/system",
      path: "/system",
      label: "系统设置",
      roles: ["admin", "staff"],

      children: [
        {
          key: "/system/baseParam",
          path: "/system/baseParam",
          label: "参数设置",
          roles: ["admin", "staff"],
          element: <BaseList />,

        },
        {
          key: "/system/userList",
          path: "/system/userList",
          label: "用户列表",
          roles: ["admin", "staff"],
          element: <UserList />,

        },

      ]
    }
  ]
}


/**
 * 登录拦截hooks
 */
export const useProxyLogin = (cb) => {
  const navigate = useNavigate();
  const location = useLocation();

  useEffect(() => {
    cb(location);
    // 每次路由变化判断当前是否登录
    if (!(localStorage.getItem("token"))) {
      // 如果没有跳转到登录页面
      navigate("/login");
    }
  }, [location.pathname]);
};
